<?php
if (!empty($_POST['cp_publish_video'])) {

// get video parameters
if (!empty($_POST['video_site']) && !empty($_POST['video_id'])) {
$generate_vid = '['.$_POST['video_site'].' '.$_POST['video_id'].']';
}
if (!empty($_POST['video_w'])) {
$generate_vid = '['.$_POST['video_site'].' '.$_POST['video_id'].' '.$_POST['video_w'].']';
}
if (!empty($_POST['video_w']) && !empty($_POST['video_h'])) {
$generate_vid = '['.$_POST['video_site'].' '.$_POST['video_id'].' '.$_POST['video_w'].' '.$_POST['video_h'].']';
}

// title exists?
if (!empty($_POST['video_title'])) {
$video_title = $_POST['video_title'];
} else {
$video_title = 'Enter a title for this video';
}

// publish post
if (!empty($_POST['video_site']) && !empty($_POST['video_id'])) {
$my_post = array();
$my_post['post_title'] = $video_title;
$my_post['post_content'] = $generate_vid;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array($this->options['videos']);
$published = wp_insert_post($my_post);
if (!empty($_POST['video_thumb'])) {
	add_post_meta($published, 'thumbnail', $_POST['video_thumb'], true);
}
}

}

if (!empty($_POST['cp_publish_video'])) {
	if ($published == false) {
	echo '<div class="error" id="message"><p>An error has occured while publishing. Please double check all fields again.</p></div>';
	} elseif ($published == true) {
	echo '<div class="updated fade msg" id="message"><p>Your video post has been published. <a href="post.php?action=edit&post='.$published.'">Edit</a> this post.</p></div>';
	}
}
?>

<div class="cpage">
<h2>QuickVideo Publisher</h2>

<form action="" method="post">

<fieldset><legend>Publishing video: required parameters</legend>
<ul>
	<li><label for="video_site">Video sharing site</label></li>
	<?php
	$sources = array('dotsub','onsmash','smotri','wat','guba','goalvideoz','mojvideo','clipsyndicate','youreporter','flash','flashvideo','funnyordie','trilulilu','d1g','reelzchannel','megavideo','msn','youtubeplaylist','mncast','hamburg1','collegehumor','jumpcut','comedycentral','reason','slideshare','teachertube','vsocial','lastfm','sumotv','123videonl','brightcove','aniboom','cellfish','tutv','yahoo','myspacetv','veoh','wandeo','glumbert','gamevideos','gametrailers','ifilm','liveleak','grouper','uncut','revver','bliptv','videotube','vimeo','metacafe','break','myvideo','dailymotion','sevenload','clipfish','google','youtube');
	sort($sources);
	?>
	<li>
	<select name="video_site" class="widefat mid">
	<option>Select a video site...</option>
	<?php foreach($sources as $value) { ?>
	<option value="<?php print $value; ?>"<?php selected($value, $_POST['video_site']); ?>><?php print ucfirst($value); ?></option>
	<?php } ?>
	</select>
	</li>
</ul>
<ul>
	<li><label for="video_id">Video ID</label></li>
	<li><input class="widefat mid" name="video_id" id="video_id" value="<?php echo $_POST['video_id']; ?>" />&nbsp;&nbsp;<a href="http://www.daburna.de/dokuwiki/doku.php/instruction"><strong>Need help?</strong></a></li>
</ul>
</fieldset>

<fieldset><legend>Publishing video: optional parameters</legend>
<ul>
	<li><label for="video_title">Post Title</label></li>
	<li><input class="widefat big" name="video_title" id="video_title" value="<?php echo $_POST['video_title']; ?>" /></li>
</ul>
<ul>
	<li><label for="video_thumb">Post Thumbnail (Enter file name only! Images must be stored in /thumbs/ folder.)</label></li>
	<li><input class="widefat mid" name="video_thumb" id="video_thumb" value="<?php echo $_POST['video_thumb']; ?>" /></li>
</ul>
<ul>
	<li><label for="video_w">Width</label></li>
	<li><input class="widefat num" name="video_w" id="video_w" value="<?php echo $_POST['video_w']; ?>" />&nbsp;&nbsp;pixels</li>
</ul>
<ul>
	<li><label for="video_h">Height</label></li>
	<li><input class="widefat num" name="video_h" id="video_h" value="<?php echo $_POST['video_h']; ?>" />&nbsp;&nbsp;pixels</li>
</ul>
</fieldset>

<input type="submit" value="Publish" name="cp_publish_video" class="button-primary" />
</form>

</div>